package org.springframework.samples.petclinic.web

import java.beans.PropertyEditorSupport

import org.springframework.samples.petclinic.Clinic
import org.springframework.samples.petclinic.ForeachIterator
import org.springframework.samples.petclinic.PetType

class PetTypeEditor(clinic: Clinic) extends PropertyEditorSupport {

  @throws(classOf[IllegalArgumentException])
  override def setAsText(text:String) = {
    for (petType <- new ForeachIterator(this.clinic.getPetTypes.iterator)) {
      if (petType.name.equals(text)) {
        setValue(petType)
      }
    } 
  }
}
